//
//  MBProgressHUD+MpHUD.m
//  Stars
//
//  Created by 魏鹏 on 16/12/14.
//  Copyright © 2016年 hst. All rights reserved.
//

#import "MBProgressHUD+MpHUD.h"


@implementation MBProgressHUD (MpHUD)

+ (void)showRemindingText:(NSString *)remind ToView:(UIView *)view {
    [MBProgressHUD showMessage:remind ToView:view];
}


//加载视图
+(void)showLoadingToView:(UIView *)view{
    [self showMessage:@"努力加载中......" ToView:view];
}

//自定义停留时间，有图
+(void)showIconMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{
    [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeIndeterminate];
}

//自定义停留时间，无图
+(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{
    [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeText];
}
/**
 *  进度条View
 */
+(void) show:(MBProgressHUDMode )mode progress:(CGFloat )progress customView:(UIView*)customView{
    if (customView == nil) customView = (UIView*)[UIApplication sharedApplication].delegate.window;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:customView animated:YES];
    hud.mode=mode;
    hud.customView = customView;
    hud.animationType = MBProgressHUDAnimationZoom;
    hud.progress = progress;
    hud.removeFromSuperViewOnHide = YES;
//    [hud show:YES];
    [hud showAnimated:YES];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message ToView:(UIView *)view {
    if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode=MBProgressHUDModeIndeterminate;
//    hud.labelText=message;/
    hud.label.text = message;
    hud.contentColor = [UIColor whiteColor];
    hud.bezelView.color = [UIColor blackColor];
    //    hud.labelFont=FONT_LB(15.0);
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    //代表需要蒙版效果
    //    hud.dimBackground = YES;
    return hud;
}

+(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time Model:(MBProgressHUDMode)model{
    
    if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
//    hud.labelText=message;
    hud.label.numberOfLines = 0;
    hud.label.text = message;
    [hud.label sizeToFit];
    hud.contentColor = [UIColor whiteColor];
    hud.bezelView.color = [UIColor blackColor];
//    hud.labelFont=FONT_LB(15);
    //模式
    hud.mode = model;
    // 代表需要蒙版效果
//    hud.dimBackground = YES;
    hud.animationType = MBProgressHUDAnimationZoom;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // X秒之后再消失
//    [hud hide:YES afterDelay:time];/
    [hud hideAnimated:YES afterDelay:time];
    
}

+ (void)hideHUDForView:(UIView *)view
{
    if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//
        [self hideHUDForView:view animated:YES];

    });

}

+ (void)hideHUD
{
    
    [self hideHUDForView:nil];

}


@end
